package ycl.base.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import ycl.base.entity.City;
import ycl.base.req.CityReq;
import ycl.base.res.CityRes;
import ycl.base.service.CityService;
import ycl.common.ApiResult;
import ycl.common.base.controller.BaseRegionController;
import ycl.common.models.base.A;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 城市设置 前端控制器
 * </p>
 *
 * @author ycl
 * @since 2022-06-22 20:06:25
 */
@RestController
@RequestMapping("/city")
@Api(tags = "城市")
@ApiSupport(order = 3)
public class CityController
		extends BaseRegionController<City, CityReq, CityRes> {

	@Resource
	private CityService cityService;

	@Override
	public ApiResult<City> getByCode(String code) {
		City city = cityService.getByCode(code, City.class);
		return ApiResult.success(city);
	}

	@Override
	public ApiResult<List<City>> getByParentCode(String code) {
		List<City> list = cityService.getByParentCode(code, City.class);
		return ApiResult.success(list);
	}

	@Override
	public ApiResult<Page<CityRes>> pageList(City city) {
		return ApiResult.success(cityService.pageList(city, CityRes.class));
	}

	@Override
	public <E extends CityReq> ApiResult<A> save(HttpServletRequest request, @Valid E e) {
		cityService.save(request, e, City.class);
		return ApiResult.success();
	}

	@Override
	public <E extends CityReq> ApiResult<A> update(HttpServletRequest request, @Valid E e) {
		cityService.update(request, e, City.class);
		return ApiResult.success();
	}
}

